/*
 * TCriticalSection.h
 *
 *  Created on: 2012-10-30
 *      Author: minhua
 */

#ifndef TCRITICALSECTION_H_
#define TCRITICALSECTION_H_

#include <QMutex>
#include <QString>
#include <QHash>

class TCriticalSection
{
public:
	TCriticalSection();

public:
    void             lock();
    void             unlock();

protected:
    int              getEnterCount();
    void             setEnterCount(int count);
private:
    QMutex                   _mutex;
    QHash<Qt::HANDLE, int>   _threadIdHash;
};

class TCriticalSectionLocker
{
public:
    TCriticalSectionLocker(TCriticalSection *criticalSection);
    ~TCriticalSectionLocker();

public:
    void             lock();
    void             unlock();

private:
    TCriticalSection          *_criticalSection;
};

#endif /* TCRITICALSECTION_H_ */
